<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="订单编号" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="partName">
        <el-input v-model="queryParams.partName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" filterable placeholder="请选择订单状态" clearable
          @keyup.enter.native="handleQuery">
          <el-option v-for="item in stateList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        <!-- <el-input v-model="queryParams.state" placeholder="请输入订单状态" clearable @keyup.enter.native="handleQuery" /> -->
      </el-form-item>
      <!-- <el-form-item label="交货日期">
        <el-date-picker v-model="daterangeDateOrder" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item> -->
      <el-form-item label="交付日期">
        <el-date-picker v-model="daterangeValidityDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="daterangeCreateDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="确认日期">
        <el-date-picker v-model="daterangeConfirmationDate" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="销售员" prop="userId">
        <el-select v-model="queryParams.userId" placeholder="请选择销售员" clearable>
          <el-option v-for="dict in dict.type.boshien_emp" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="客户" prop="partnerId">
        <el-select v-model="queryParams.partnerId" filterable placeholder="请选择客户" clearable
          @keyup.enter.native="handleQuery" :filter-method="customerfilterMethod">
          <el-option v-for="item in customerdata" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        <!-- <el-input v-model="queryParams.partnerId" placeholder="请输入客户" clearable @keyup.enter.native="handleQuery" /> -->
      </el-form-item>
      <!-- <el-form-item label="发票地址" prop="partnerInvoiceId">
        <el-input v-model="queryParams.partnerInvoiceId" placeholder="请输入发票地址" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="送货地址" prop="partnerShippingId">
        <el-input v-model="queryParams.partnerShippingId" placeholder="请输入送货地址" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="价格表" prop="pricelistId">
        <el-input v-model="queryParams.pricelistId" placeholder="请输入价格表" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="不含税金额" prop="amountUntaxed">
        <el-input v-model="queryParams.amountUntaxed" placeholder="请输入不含税金额" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="含税金额" prop="amountTax">
        <el-input v-model="queryParams.amountTax" placeholder="请输入含税金额" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="总计金额" prop="amountTotal">
        <el-input v-model="queryParams.amountTotal" placeholder="请输入总计金额" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="付款条件" prop="paymentTermId">
        <el-input v-model="queryParams.paymentTermId" placeholder="请输入付款条件" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="销售频道" prop="teamId">
        <el-input v-model="queryParams.teamId" placeholder="请输入销售频道" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建者" prop="createUid">
        <el-select v-model="queryParams.createUid" placeholder="请选择创建者" clearable>
          <el-option v-for="dict in dict.type.boshien_emp" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="最后更新者" prop="writeUid">
        <el-select v-model="queryParams.writeUid" placeholder="请选择最后更新者" clearable>
          <el-option v-for="dict in dict.type.boshien_emp" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="最后更新时间" prop="writeDate">
        <el-date-picker clearable v-model="queryParams.writeDate" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择最后更新时间">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="本地/海外" prop="warehouseId">
        <el-input v-model="queryParams.warehouseId" placeholder="请输入本地/海外" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="Procurement Group" prop="procurementGroupId">
        <el-input v-model="queryParams.procurementGroupId" placeholder="请输入Procurement Group" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="交货条件" prop="deliveryConditions">
        <el-input v-model="queryParams.deliveryConditions" placeholder="请输入交货条件" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="指令单号" prop="instructionOrder">
        <el-input v-model="queryParams.instructionOrder" placeholder="请输入指令单号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="合同号" prop="contractNo">
        <el-input v-model="queryParams.contractNo" placeholder="请输入合同号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="提供增值发票" prop="isProvideInvoice">
        <el-input v-model="queryParams.isProvideInvoice" placeholder="请输入提供增值发票" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="承担运费" prop="isProvideFreight">
        <el-input v-model="queryParams.isProvideFreight" placeholder="请输入承担运费" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="合同签订日期">
        <el-date-picker v-model="daterangeContractDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="交货条件" prop="deliveryConditionsId">
        <el-input v-model="queryParams.deliveryConditionsId" placeholder="请输入交货条件" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="含税" prop="isTax">
        <el-input v-model="queryParams.isTax" placeholder="请输入含税" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="银行" prop="worldchampBankId">
        <el-input v-model="queryParams.worldchampBankId" placeholder="请输入银行" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="总金额大写" prop="amountTotalDaxie">
        <el-input v-model="queryParams.amountTotalDaxie" placeholder="请输入总金额大写" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="扣减" prop="isInventory">
        <el-input v-model="queryParams.isInventory" placeholder="请输入扣减" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="Addquotation">新增报价单</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:order:add']">新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:order:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:order:remove']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange" @row-click="getDetail">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <el-table-column label="订单编号" align="center" prop="name" />
      <el-table-column label="客户" align="center" prop="partnerName" />
      <el-table-column label="合同号" align="center" prop="contractNo" />
      <el-table-column label="合同签订日期" align="center" prop="contractDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="订单日期" align="center" prop="dateOrder" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dateOrder, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="交付日期" align="center" prop="validityDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validityDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="订单确认日期" align="center" prop="confirmationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.confirmationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="销售员" align="center" prop="userId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.boshien_emp" :value="scope.row.userId" />
        </template> 
      </el-table-column>

      <!-- <el-table-column label="发票地址" align="center" prop="partnerInvoiceId" /> -->
      <!-- <el-table-column label="送货地址" align="center" prop="partnerShippingId" /> -->
      <!-- <el-table-column label="价格表" align="center" prop="pricelistId" /> -->
      <!-- <el-table-column label="发票状态" align="center" prop="invoiceStatus" /> -->
      <!-- <el-table-column label="条款和条件" align="center" prop="note" /> -->
      <!-- <el-table-column label="不含税金额" align="center" prop="amountUntaxed" /> -->
      <!-- <el-table-column label="含税金额" align="center" prop="amountTax" /> -->
      <el-table-column label="总计金额(元)" align="center" prop="amountTotal" />
      <!-- <el-table-column label="付款条件" align="center" prop="paymentTermId" /> -->
      <!-- <el-table-column label="销售频道" align="center" prop="teamId" /> -->
      <!--<el-table-column label="创建者" align="center" prop="createUid">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.boshien_emp" :value="scope.row.createUid" />
        </template>
      </el-table-column>
      <el-table-column label="最后更新者" align="center" prop="writeUid">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.boshien_emp" :value="scope.row.writeUid" />
        </template>
      </el-table-column>
      <el-table-column label="最后更新时间" align="center" prop="writeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.writeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="本地/海外" align="center" prop="warehouseId" /> -->

      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_state" :value="scope.row.state" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="Procurement Group" align="center" prop="procurementGroupId" /> -->
      <!-- <el-table-column label="交货条件" align="center" prop="deliveryConditions" /> -->
      <!-- <el-table-column label="指令单号" align="center" prop="instructionOrder" /> -->

      <!-- <el-table-column label="运输方式" align="center" prop="transportType" /> -->
      <!-- <el-table-column label="提供增值发票" align="center" prop="isProvideInvoice" />
      <el-table-column label="承担运费" align="center" prop="isProvideFreight" />
      -->
      <!-- <el-table-column label="交货条件" align="center" prop="deliveryConditionsId" />
      <el-table-column label="含税" align="center" prop="isTax" /> -->
      <!-- <el-table-column label="银行" align="center" prop="worldchampBankId" /> -->
      <!-- <el-table-column label="总金额大写" align="center" prop="amountTotalDaxie" /> -->
      <!-- <el-table-column label="扣减" align="center" prop="isInventory" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" @click.stop>
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click.stop="getDetail(scope.row)">订单详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="EditSale(scope.row)"
            v-show="scope.row.state == 'draft'">修改</el-button>

          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']">ces</el-button> -->
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="sureState(scope.row)"
            v-hasPermi="['system:order:edit']">确认销售订单</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="cancelState(scope.row)"
            v-hasPermi="['system:order:edit']">取消销售订单</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-delete" @click.stop="handleDelete(scope.row)"
            v-hasRole="['admin']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改销售订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="订单编号" prop="name">
          <el-input v-model="form.name" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="订单状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入订单状态" />
        </el-form-item>
        <el-form-item label="订单日期" prop="dateOrder">
          <el-date-picker clearable v-model="form.dateOrder" type="date" value-format="yyyy-MM-dd" placeholder="请选择订单日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交付日期" prop="validityDate">
          <el-date-picker clearable v-model="form.validityDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择交付日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable v-model="form.createDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单确认日期" prop="confirmationDate">
          <el-date-picker clearable v-model="form.confirmationDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择订单确认日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="销售员" prop="userId">
          <el-select v-model="form.userId" placeholder="请选择销售员">
            <el-option v-for="dict in dict.type.boshien_emp" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户id" prop="partnerId">
          <el-input v-model="form.partnerId" placeholder="请输入客户id" />
        </el-form-item>
        <el-form-item label="发票地址" prop="partnerInvoiceId">
          <el-input v-model="form.partnerInvoiceId" placeholder="请输入发票地址" />
        </el-form-item>
        <el-form-item label="送货地址" prop="partnerShippingId">
          <el-input v-model="form.partnerShippingId" placeholder="请输入送货地址" />
        </el-form-item>
        <el-form-item label="价格表" prop="pricelistId">
          <el-input v-model="form.pricelistId" placeholder="请输入价格表" />
        </el-form-item>
        <el-form-item label="条款和条件" prop="note">
          <el-input v-model="form.note" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="不含税金额" prop="amountUntaxed">
          <el-input v-model="form.amountUntaxed" placeholder="请输入不含税金额" />
        </el-form-item>
        <el-form-item label="含税金额" prop="amountTax">
          <el-input v-model="form.amountTax" placeholder="请输入含税金额" />
        </el-form-item>
        <el-form-item label="总计金额" prop="amountTotal">
          <el-input v-model="form.amountTotal" placeholder="请输入总计金额" />
        </el-form-item>
        <el-form-item label="付款条件" prop="paymentTermId">
          <el-input v-model="form.paymentTermId" placeholder="请输入付款条件" />
        </el-form-item>
        <el-form-item label="销售频道" prop="teamId">
          <el-input v-model="form.teamId" placeholder="请输入销售频道" />
        </el-form-item>
        <el-form-item label="创建者" prop="createUid">
          <el-select v-model="form.createUid" placeholder="请选择创建者">
            <el-option v-for="dict in dict.type.boshien_emp" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最后更新者" prop="writeUid">
          <el-select v-model="form.writeUid" placeholder="请选择最后更新者">
            <el-option v-for="dict in dict.type.boshien_emp" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户" prop="partnerId">
          <!-- <el-input v-model="form.partnerId" placeholder="请输入客户"></el-input> -->
          <el-select v-model="form.partnerId" filterable placeholder="请选择客户" >
            <el-option v-for="item in customerdata" :key="item.id" :label="item.name" :value="parseInt(item.id)">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="最后更新时间" prop="writeDate">
          <el-date-picker clearable v-model="form.writeDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择最后更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="本地/海外" prop="warehouseId">
          <el-input v-model="form.warehouseId" placeholder="请输入本地/海外" />
        </el-form-item>
        <el-form-item label="Procurement Group" prop="procurementGroupId">
          <el-input v-model="form.procurementGroupId" placeholder="请输入Procurement Group" />
        </el-form-item>
        <el-form-item label="交货条件" prop="deliveryConditions">
          <el-input v-model="form.deliveryConditions" placeholder="请输入交货条件" />
        </el-form-item>
        <el-form-item label="指令单号" prop="instructionOrder">
          <el-input v-model="form.instructionOrder" placeholder="请输入指令单号" />
        </el-form-item>
        <el-form-item label="合同号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同号" />
        </el-form-item>
        <el-form-item label="提供增值发票" prop="isProvideInvoice">
          <el-input v-model="form.isProvideInvoice" placeholder="请输入提供增值发票" />
        </el-form-item>
        <el-form-item label="承担运费" prop="isProvideFreight">
          <el-input v-model="form.isProvideFreight" placeholder="请输入承担运费" />
        </el-form-item>
        <el-form-item label="合同签订日期" prop="contractDate">
          <el-date-picker clearable v-model="form.contractDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择合同签订日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交货条件" prop="deliveryConditionsId">
          <el-input v-model="form.deliveryConditionsId" placeholder="请输入交货条件" />
        </el-form-item>
        <el-form-item label="含税" prop="isTax">
          <el-input v-model="form.isTax" placeholder="请输入含税" />
        </el-form-item>
        <el-form-item label="银行" prop="worldchampBankId">
          <el-input v-model="form.worldchampBankId" placeholder="请输入银行" />
        </el-form-item>
        <el-form-item label="总金额大写" prop="amountTotalDaxie">
          <el-input v-model="form.amountTotalDaxie" placeholder="请输入总金额大写" />
        </el-form-item>
        <el-form-item label="扣减" prop="isInventory">
          <el-input v-model="form.isInventory" placeholder="请输入扣减" />
        </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>

  </div>
</template>

<script>
import { listPartner } from '@/api/system/partner.js'
import { listOrder, getOrder, delOrder, addOrder, updateOrder, cancelState, sureState } from "@/api/system/order";
import saleorderdetail from "@/views/system/saleorderdetail/index";
import salequotation from "@/views/system/salequotation/index";
import saleedit from "@/views/system/saleedit/index";

export default {
  name: "Order",

  dicts: ['order_state', 'boshien_emp'],


  data() {
    return {
      //订单状态
      stateList: [
        {
          id: 'sale',
          name: '销售订单'
        },
        {
          id: 'draft',
          name: '报价单'
        },
        {
          id: 'cancel',
          name: '已取消'
        },
      ],
      // 客户
      customerdata: [],
      dialogVisible: false,
      result: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 扣减时间范围
      daterangeDateOrder: [],
      // 扣减时间范围
      daterangeValidityDate: [],
      // 扣减时间范围
      daterangeCreateDate: [],
      // 扣减时间范围
      daterangeConfirmationDate: [],
      // 扣减时间范围
      daterangeContractDate: [],
      // 查询参数
      queryParams: {
        partName: null,
        pageNum: 1,
        pageSize: 10,
        name: null,
        state: 'draft',
        dateOrder: null,
        validityDate: null,
        createDate: null,
        confirmationDate: null,
        userId: null,
        partnerId: null,
        partnerInvoiceId: null,
        partnerShippingId: null,
        pricelistId: null,
        invoiceStatus: null,
        note: null,
        amountUntaxed: null,
        amountTax: null,
        amountTotal: null,
        paymentTermId: null,
        teamId: null,
        createUid: null,
        writeUid: null,
        writeDate: null,
        warehouseId: null,
        procurementGroupId: null,
        deliveryConditions: null,
        instructionOrder: null,
        contractNo: null,
        transportType: null,
        isProvideInvoice: null,
        isProvideFreight: null,
        contractDate: null,
        deliveryConditionsId: null,
        isTax: null,
        worldchampBankId: null,
        amountTotalDaxie: null,
        isInventory: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "订单编号不能为空", trigger: "blur" }
        ],
        dateOrder: [
          { required: true, message: "订单日期不能为空", trigger: "blur" }
        ],
        partnerId: [
          { required: true, message: "客户id不能为空", trigger: "blur" }
        ],
        partnerInvoiceId: [
          { required: true, message: "发票地址不能为空", trigger: "blur" }
        ],
        partnerShippingId: [
          { required: true, message: "送货地址不能为空", trigger: "blur" }
        ],
        pricelistId: [
          { required: true, message: "价格表不能为空", trigger: "blur" }
        ],
        warehouseId: [
          { required: true, message: "本地/海外不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.customerList()
  },
  methods: {
    // 新增报价单
    Addquotation() {
      this.$router.push({
        path: "/salequotation",
        component: salequotation,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        // query: { listId: 574 },
        query: {},

      });

    },
    // 编辑销售订单
    EditSale(row) {
      const id = row.id
      this.$router.push({
        path: "/saleedit",
        component: saleedit,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        query: { listId: id },

      });

    },
    // 取消销售订单
    cancelState(row) {
      const id = row.id
      cancelState(id).then(res => {
        // console.log(res);
      })
      this.getList();
    },
    // 确认销售订单
    sureState(row) {
      const id = row.id
      sureState(id).then(res => {
        // console.log(res);
      })
      this.getList();
    },
    // 下拉框选择客户
    customerList() {
      listPartner(this.queryParams).then(res => {
        // console.log(res);
        this.customerdata = res.rows
        // console.log(this.customerdata);

      })
    },
    // 客户搜索
    customerfilterMethod(node, val) {

      // console.log('val', val, 'node', node)
      // console.log(node);
      const que = {
        name: node,
        pageSize: 100,
        customer: 't'
      }
      // console.log(que);
      listPartner(que).then(res => {
        // console.log(res);
        this.customerdata = res.rows
      })
    },
    // 创建时间和创建人
    getcreatNow() {
      var date = new Date();
      var data1 = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
      this.form.createDate = data1
      // console.log(this.form.createDate);
      this.form.createUid = this.$store.state.user.name
      this.form.writeDate = data1
      // console.log(this.form.updateTime);
      this.form.writeUid = this.$store.state.user.name
      // console.log(this.$store.state.user.name);
      return data1

    },
    // 更新时间和更新人
    getupdateNow() {
      var date = new Date();
      var data1 = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
      this.form.writeDate = data1
      // console.log(this.form.updateTime);
      this.form.writeUid = this.$store.state.user.name
      // console.log(this.$store.state.user.name);
      return data1

    },
    /** 查询销售订单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeDateOrder && '' != this.daterangeDateOrder) {
        this.queryParams.params["beginDateOrder"] = this.daterangeDateOrder[0];
        this.queryParams.params["endDateOrder"] = this.daterangeDateOrder[1];
      }
      if (null != this.daterangeValidityDate && '' != this.daterangeValidityDate) {
        this.queryParams.params["beginValidityDate"] = this.daterangeValidityDate[0];
        this.queryParams.params["endValidityDate"] = this.daterangeValidityDate[1];
      }
      if (null != this.daterangeCreateDate && '' != this.daterangeCreateDate) {
        this.queryParams.params["beginCreateDate"] = this.daterangeCreateDate[0];
        this.queryParams.params["endCreateDate"] = this.daterangeCreateDate[1];
      }
      if (null != this.daterangeConfirmationDate && '' != this.daterangeConfirmationDate) {
        this.queryParams.params["beginConfirmationDate"] = this.daterangeConfirmationDate[0];
        this.queryParams.params["endConfirmationDate"] = this.daterangeConfirmationDate[1];
      }
      if (null != this.daterangeContractDate && '' != this.daterangeContractDate) {
        this.queryParams.params["beginContractDate"] = this.daterangeContractDate[0];
        this.queryParams.params["endContractDate"] = this.daterangeContractDate[1];
      }

      // console.log(this.queryParams);
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 查询详情按钮
    getDetail(row) {
      const id = row.id
      this.$router.push({
        path: "/saleorderdetail",
        component: saleorderdetail,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        // query: { listId: 5745 },
        query: { listId: id },

      });

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        state: null,
        dateOrder: null,
        validityDate: null,
        createDate: null,
        confirmationDate: null,
        userId: null,
        partnerId: null,
        partnerInvoiceId: null,
        partnerShippingId: null,
        pricelistId: null,
        invoiceStatus: null,
        note: null,
        amountUntaxed: null,
        amountTax: null,
        amountTotal: null,
        paymentTermId: null,
        teamId: null,
        createUid: null,
        writeUid: null,
        writeDate: null,
        warehouseId: null,
        procurementGroupId: null,
        deliveryConditions: null,
        instructionOrder: null,
        contractNo: null,
        transportType: null,
        isProvideInvoice: null,
        isProvideFreight: null,
        contractDate: null,
        deliveryConditionsId: null,
        isTax: null,
        worldchampBankId: null,
        amountTotalDaxie: null,
        isInventory: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.pageSize=100
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeDateOrder = [];
      this.daterangeValidityDate = [];
      this.daterangeCreateDate = [];
      this.daterangeConfirmationDate = [];
      this.daterangeContractDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加销售订单";
      this.getcreatNow()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        // console.log(response);
        this.form = response.data;
        this.open = true;
        this.title = "修改销售订单";
        this.getupdateNow()
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除销售订单编号为"' + ids + '"的数据项？').then(function () {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
